|
|
|
|
|
|
|
amount of paint needed to paint a room. Such a program can contain a form that allows the painter to enter the length and width of the room, the height of the ceiling, and the coverage and cost of a single can of paint. Your program can then calculate the number of gallons of paint required and the cost of the paint. An example of the form for such a program is shown in Figure 9.2. The actual code to perform the calculations is shown in Listing 9.1. |
|
|
|
|
|
|
|
|
Figure 9.2
Multiplication and division are used to
determine the amount of paint needed for a room. |
|
|
|
|
|
|
|
|
Listing 9.1 MATHEX.ZIPPainting Cost Estimate Using Multiplication and Division Operators |
|
|
|
|
|
|
|
|
Private Sub cmdCalculate_Click()
Dim fRoomLength As Single
Dim fRoomWidth As Single
Dim fRoomHeight As Single
Dim fCanCoverage As Single
Dim cCanCost As Currency
Dim fRoomPerimeter As Single
Dim fWallArea As Single
Dim fNumGallons As Single
Dim cProjCost As Currency
fRoomLength = Val(txtLength.Text)
fRoomWidth = Val(txtWidth.Text)
fRoomHeight = Val(txtHeight.Text)
fCanCoverage = Val(txtCoverage.Text)
cCanCost = Val(txtCost.Text)
fRoomPerimeter = 2 * fRoomLength + 2 * fRoomWidth
fWallArea = fRoomPerimeter * fRoomHeight
fNumGallons = fWallArea / fCanCoverage
cProjCost = fNumGallons * cCanCost
txtGallons.Text = fNumGallons
txtTotalCost.Text = cProjCost
End Sub |
|
|
|
|
|
|
|
|
 To test this code, start by creating a new EXE project in Visual Basic. Add seven text boxes to the form; set their Name properties to txtLength, txtWidth, txtHeight, txtCoverage, txtCost, txtGallons, and txtTotalCost. The first five are to accept information from the user; the last two will report information back to the user. You may want to add descriptive Label controls beside each text box. |
|
|
|
|
|